﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;

namespace QT.SEO
{
    /// <summary>
    /// 操作软件设置的类
    /// </summary>
    public class Setting
    {
        /// <summary>
        /// 获取所有设置项目和设定值
        /// </summary>
        /// <returns>DataTable</returns>
        public static DataTable GetAll()
        {
            string sql = "select [item],[content] from [QT_Basic_Setting]";

            DataTable dt = new QT.DBO.OleDBHelper(myDB.connstring).DataTable(sql);

            return dt;
        }

        /// <summary>
        /// 获取指定项目的设定值
        /// </summary>
        /// <param name="item">需要查询的项目</param>
        /// <returns>string</returns>
        public static string Get(string item)
        {
            string sql = "select [content] from [QT_Basic_Setting] where [item]='" + item + "'";

            DataTable dt = new QT.DBO.OleDBHelper(myDB.connstring).DataTable(sql);

            return dt.Rows[0]["content"].ToString();
        }
        
        /// <summary>
        /// 修改指定项目的设定值
        /// </summary>
        /// <param name="item">需要修改的项目</param>
        /// <param name="value">修改后的值</param>
        /// <returns>bool</returns>
        public static bool Update(string item,string value)
        {
            string sql = "update [QT_Basic_Setting] set [content]='" + value + "' where [item]='" + item + "'";

            if (new QT.DBO.OleDBHelper(myDB.connstring).ExecuteNonQuery(sql) > 0) return true;

            return false;
        }
    }
}
